<extend name="Public/base" />

<block name="body">
    <include file="Public:sui" />
    <!-- 标题栏 -->
    <div class="main-title">
        <h2>{$meta_title}</h2>
    </div>
    <div class="cf">
        <div class="fl">
            总计：<span style="color: green;font-size: 18px;">{$totalfee|default=0}</span> 元
        </div>
    <!-- 高级搜索 -->
    <div class="search-form fr cf">
        <div class="sleft">
            <select name="type" id="type">
                <option value="0" >==全部类型==</option>
                <volist name="_type" id="vo">
                    <option value="{$i}" <php>if($i==I("type"))echo 'selected="selected"';</php>>{$vo}</option>
                </volist>
            </select>
        </div>
        <div class="sleft">
            <select name="status" id="status">
                <option value="" >==全部状态==</option>
                <volist name="_status" id="vo">
                    <option value="{$i-1}" <php>if(($i-1)==I("status")&&strlen(I("status"))>0)echo 'selected="selected"';</php>>{$vo}</option>
                </volist>
            </select>
        </div>
        <div class="sleft">
            <a class="sch-btn" href="javascript:;" id="search" url="{:U('index')}"><i class="btn-search"></i></a>
        </div>
    </div>
    </div>

    <!-- 数据列表 -->
    <div class="data-table table-striped">
        <table class="">
            <thead>
            <tr>
                <th class="row-selected row-selected"><input class="check-all" type="checkbox"/></th>
                <th class="">学生</th>
                <th class="">课程</th>
                <th class="">课时数</th>
                <th class="">开始上课时间</th>
                <th class="">类型</th>
                <th class="">状态</th>
                <th class="">费用</th>
                <th class="">缴费渠道</th>
                <th class="">缴费时间</th>
                <th class="">经手</th>
                <th class="">操作</th>
            </tr>
            </thead>
            <tbody>
            <notempty name="_list">
                <php>
                    $total = 0;
                </php>
                <volist name="_list" id="vo">
                    <php>
                        $total += $vo['fee'];
                        if(!empty($vo['grade_id'])){
                            $res = _checkGradeStudent($vo['grade_id'], $vo['sid']);
                            $vo['status'] = $res?1:2;
                        }
                    </php>
                    <tr>
                        <td><input class="ids" type="checkbox" name="id[]" value="{$vo.id}" /></td>
                        <td>{$vo.sid|_getStudentName}</td>
                        <eq name="vo.type" value="2">
                            <td colspan="3">{$vo.grade_id|_getGradeName}</td>
                            <else/>
                            <td>{$vo.course_id|_getCourseTitle}</td>
                            <td>{$vo.class_hour}</td>
                            <td>{$vo.class_start_time|time_format}</td>
                        </eq>
                        <td>
                            <switch name="vo.type">
                                <case value="1">一对一</case>
                                <case value="2">一对多</case>
                            </switch>
                        </td>
                        <td>
                            <switch name="vo.status">
                                <case value="0"><span style="color: #FFA500;">待缴费</span></case>
                                <case value="1"><span style="color: green;">进行中</span></case>
                                <case value="2"><span style="color: #B0B0B0;">已结束</span></case>
                            </switch>
                        </td>
                        <td>{$vo.fee}</td>
                        <td>
                            <gt name="vo.status" value="0">
                            <volist name="_pay_method" id="paymethod" key="k">
                                <php>if($vo['pay_method']==$k){echo $paymethod;}</php>
                            </volist>
                            </gt>
                        </td>
                        <td><gt name="vo.status" value="0">{$vo.pay_time|time_format}</gt></td>
                        <td>{$vo.admin_id|_getNickname}</td>
                        <td>
                            <eq name="vo.type" value="2">
                                <!--<a href="{:U('Programme/add?type=2&grade_id='.$vo['grade_id'])}" class="authorize">教学计划</a>-->
                                <else/>
                                <a href="{:U('Programme/add?id='.$vo['id'])}" class="authorize">教学计划</a>
                            </eq>


                            <eq name="vo.status" value="0">
                            <a href="{:U('delete?id='.$vo['id'])}" class="confirm ajax-get">删除</a>
                            <a href="javascript:void(0);" class="authorize shoufei" data_sid="{$vo.sid}" data_id="{$vo.id}" data_fee="{$vo.fee}" data="{$vo.sid|_getStudentName}-{$vo.course_id|_getCourseTitle}-{$vo.class_start_time|time_format}-{$vo.class_hour}">收费</a>
                            </eq>
                        </td>
                    </tr>
                </volist>
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td colspan="3" style="text-align: center;font-weight: bold;">小计</td>
                    <td colspan="3">{$total}</td>
                    <td></td>
                    <td></td>
                </tr>
                <else/>
                <td colspan="14" class="text-center"> aOh! 暂时还没有内容! </td>
            </notempty>
            </tbody>
        </table>
    </div>
    <div class="page">
        {$_page}
    </div>
    <!-- Modal-->
    <div id="myModal" tabindex="-1" role="dialog" data-hasfoot="false" class="sui-modal hide fade">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" data-dismiss="modal" aria-hidden="true" class="sui-close">×</button>
                    <h4 id="myModalLabel" class="modal-title"></h4>
                </div>
                <div class="modal-body">
                    <form class="sui-form form-horizontal">
                        <div class="control-group">
                            <label  class="control-label">金额：</label>
                            <div class="controls" id="modal_fee" style="font-size: 24px;">

                            </div>
                        </div>
                        <div class="control-group">
                            <label for="inputPaymethod" class="control-label">缴费方式：</label>
                            <div class="controls">
                                <select name="inputPaymethod" id="inputPaymethod">
                                    <volist name="_pay_method" id="paymethod" key="k">
                                    <option value="{$k}">{$paymethod}</option>
                                    </volist>
                                </select>

                            </div>
                        </div>
                    </form>

                </div>
                <div class="modal-footer">
                    <button type="button" data-ok="modal" class="sui-btn btn-primary btn-large" id="_jiaofei">确 定</button>
                    <button type="button" data-dismiss="modal" class="sui-btn btn-default btn-large">取 消</button>
                </div>
            </div>
        </div>
    </div>
    <input type="hidden"  id="data_id" value="" >
    <input type="hidden"  id="data_sid" value="" >
</block>

<block name="script">
    <script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>

    <script type="text/javascript">

        $(function(){
            $(".shoufei").click(function(){
                var title = $(this).attr("data");
                var fee = $(this).attr("data_fee");
                var data_id = $(this).attr("data_id");
                var data_sid = $(this).attr("data_sid");
                $("#myModalLabel").html(title);
                $("#modal_fee").html(fee);
                $("#data_id").val(data_id);
                $("#data_sid").val(data_sid);
                $("#myModal").modal('show');
            });

            $("#_jiaofei").click(function(){
                var data_id = $("#data_id").val();
                var inputPaymethod = $("#inputPaymethod").val();
                var data_sid = $("#data_sid").val();
                $.ajax({
                    type: 'POST',
                    url: "{:U('ajaxPay')}",
                    data: "sid="+data_sid+"&data_id="+data_id+"&pay_method="+inputPaymethod,
                    success: function (res) {
                        if(res.status==1){
                            window.location.reload();
                        }else{
                            alert("服务器繁忙，请稍后再试！");
                        }
                    }
                });
            });
        })

        //搜索功能
        $("#search").click(function(){
            var url = $(this).attr('url');
            var query  = $('.search-form').find('input').serialize();
            query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
            query = query.replace(/^&/g,'');
            if( url.indexOf('?')>0 ){
                url += '&' + query;
            }else{
                url += '?' + query;
            }

            var type = $("#type").val();
            var status = $("#status").val();
            window.location.href = url + '&type='+type + '&status=' + status;
        });
        //回车搜索
        $(".search-input").keyup(function(e){
            if(e.keyCode === 13){
                $("#search").click();
                return false;
            }
        });
        //导航高亮
        highlight_subnav('{:U('Charge/index')}');
    </script>
</block>
